home *** CD-ROM | disk | FTP | other *** search
/ Developer CD Series 1996 May: Tool Chest / Developer CD Series May 1996 (Tool Chest) (Apple Computer) (1996).iso / Sample Code / Http Server / •OT_Classes / TCachedStorage.cp < prev    next >
Encoding:
Text File  |  1996-01-11  |  2.9 KB  |  92 lines  |  [TEXT/CWIE]

  1. //    TCachedStorage.cp - custom memory  managemnent
  2. // 
  3. // Apple Macintosh Developer Technical Support
  4. // Written by:  Vinne Moscaritolo
  5. //
  6. //  Copyright (work in progress)  Apple Computer, Inc All rights reserved.
  7. //
  8. // You may incorporate this sample code into your applications without
  9. // restriction, though the sample code has been provided "AS IS" and the
  10. // responsibility for its operation is 100% yours.  However, what you are
  11. // not permitted to do is to redistribute the source as "DSC Sample Code"
  12. // after having made changes. If you're going to re-distribute the source,
  13. // we require that you make it clear in the source that the code was
  14. // descended from Apple Sample Code, but that you've made changes.
  15. // 
  16.  
  17. #include "TCachedStorage.h"
  18.  
  19.  
  20. // ===========================================================================
  21. //    Static member variables
  22. // ===========================================================================
  23. TList                     TStorageManager::fgPurgeList;     // List of stacks
  24. TStorageManager::Init     TStorageManager::fgInit;         // Storage manager Init object
  25.  
  26.  
  27. struct TPurgeHandler : public TLink
  28. {
  29.     TPurgeHandler(TLifo* theCache) : fCacheList(theCache) {};
  30.     TLifo* fCacheList;
  31. };
  32.  
  33. // ---------------------------------------------------------------------------
  34. //     TStorageManager::Init::~Init
  35. // ---------------------------------------------------------------------------
  36. //    Destructor.   cleans up after storage manager was used
  37.  
  38. TStorageManager::Init::~Init(void)
  39. {
  40.     TPurgeHandler *purgeObject;
  41.  
  42. // Free up all Stacks
  43.     TStorageManager::Purge();
  44.  
  45. // dispose of any Handlers..
  46. // BUG ****
  47. //    while( purgeObject = (TPurgeHandler*) fgPurgeList.RemoveFirst() ) 
  48. //            delete purgeObject;
  49. }
  50.  
  51.  
  52. // ---------------------------------------------------------------------------
  53. //     TStorageManager::Register( theCache )
  54. // ---------------------------------------------------------------------------
  55. //    Register cache Purge Object 
  56. //
  57.  
  58. void TStorageManager::Register( TLifo* theCache )
  59.  {
  60.    fgPurgeList.Add((TLink*) new TPurgeHandler(theCache) );
  61.  }
  62.  
  63. // ---------------------------------------------------------------------------
  64. //    UnRegister( theCache )
  65. // ---------------------------------------------------------------------------
  66. //    UnRegister cache Purge Object 
  67. //
  68.  
  69. void TStorageManager::UnRegister( TLifo* theCache )
  70.  {
  71.    fgPurgeList.Remove((TLink*)theCache); 
  72.  }
  73.  
  74. // ---------------------------------------------------------------------------
  75. //     TStorageManager::Purge()
  76. // ---------------------------------------------------------------------------
  77. //    Purge all cache registered areas
  78. //
  79.  
  80. void TStorageManager::Purge()
  81. {
  82.     TPurgeHandler *purgeObject;
  83.              void *deadObject;
  84.     
  85.     for(purgeObject = (TPurgeHandler*) fgPurgeList.GetFirst();    
  86.         purgeObject;     
  87.         purgeObject = (TPurgeHandler*) purgeObject->Next())
  88.             while(deadObject = purgeObject->fCacheList->Dequeue())
  89.                 TStorageManager::Free (deadObject);    
  90. }; 
  91.  
  92.